package com.uade.magicCompany.dao;

import java.util.List;

import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;

import com.uade.magicCompany.entities.AtraccionEntity;


public class DAOAtraccionesImpl extends
		AbstractBaseGenericDAOImpl<AtraccionEntity, Long> implements DAOAtracciones {

	@Override
	public List<AtraccionEntity> buscarAtraccionesPorParque(Long id) {
		// Get the entity manager for the tests.
		emf = Persistence.createEntityManagerFactory("JEE6Demo-Persistence");
		em = emf.createEntityManager();
		try {
			// Get a new transaction
			EntityTransaction trx = em.getTransaction();

			// Start the transaction
			trx.begin();
			// Get list
			Query query = em
					.createQuery(
							"SELECT c FROM AtraccionEntity c WHERE c.parque.id = :idParque").setParameter("idParque", id);
			List<AtraccionEntity> atracciones = (List<AtraccionEntity>) query
					.getResultList();
			// Commit and end the transaction
			trx.commit();
				return atracciones;

		} catch (RuntimeException e) {
			// if (trx != null && trx.isActive()) {
			// trx.rollback();
			// }
			throw e;
		} finally {
			// Close the manager
			em.close();

		}
	}

}
